package cn.bone.async.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.concurrent.TimeUnit;

/**
 * Created by MD-01 on 2017/3/28.
 */
@Service
public class DemoService {

    private Logger logger = LoggerFactory.getLogger("业务处理");

    public String say(String name){

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("Slow task executed");
        return "hello " + name;
    }

    @Async
    public ListenableFuture<String> execute(){
        logger.info("execute");
        String name = name();
        return new AsyncResult(name);
    }

    private String name(){

        logger.info("name");
        return "戴泽";
    }
}
